home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_203 / gurusguide / copper.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  5KB  |  186 lines

  1. /************************************************************************
  2. **********                                                     **********
  3. **********           C O P P E R   I N T E R R U P T           **********
  4. **********           -------------------------------           **********
  5. **********                                                     **********
  6. **********        Copyright (C) 1988 Sassenrath Research       **********
  7. **********                All Rights Reserved.                 **********
  8. **********                                                     **********
  9. **********    Example from the "Guru's Guide, Meditation #1"   **********
  10. **********                                                     **********
  11. *************************************************************************
  12. **                                                                     **
  13. **                            - NOTICE -                               **
  14. **                                                                     **
  15. **  The "Guru's Guide, Meditation #1" contains detailed information    **
  16. **  about Amiga interrupts as well as a complete discussion of this    **
  17. **  and other examples.  Meditation #1 and all of its examples were    **
  18. **  written by Carl Sassenrath, the architect of Amiga's multitasking  **
  19. **  operating system.  Copies of the "Guru's Guide" may be obtained    **
  20. **  from:                                                              **
  21. **           GURU'S GUIDE, P.O. BOX 1510, UKIAH, CA 95482              **
  22. **                                                                     **
  23. **  Please include a check for $14.95, plus $1.50 shipping ($4.00 if   **
  24. **  outside North America).  CA residents add 6% sales tax.            **
  25. **                                                                     **
  26. **  This example may be used for any purposes, commercial, personal,   **
  27. **  public, and private, so long as ALL of the above text, copyright,  **
  28. **  mailing address, and this notice are retained in their entirety.   **
  29. **                                                                     **
  30. **  THIS EXAMPLE IS PROVIDED WITHOUT WARRANTY OF ANY KIND.             **
  31. **                                                                     **
  32. ************************************************************************/
  33.  
  34. /*
  35. **  COMPILATION NOTE:
  36. **
  37. **  Compiled under MANX AZTEC C 3.6A.  Use the +L compiler option
  38. **  and the "c32" library.  Link with intrsup.o.
  39. */
  40.  
  41.  
  42. #include <exec/exec.h>
  43. #include <hardware/custom.h>
  44. #include <hardware/intbits.h>
  45. #include <graphics/gfxmacros.h>
  46. #include <graphics/copper.h>
  47. #include <intuition/intuition.h>
  48.  
  49. APTR GfxBase = NULL;
  50. APTR IntuitionBase = NULL;
  51.  
  52. struct Task *ATask = NULL;
  53. struct Interrupt *Intr = NULL;
  54. struct Screen *AScreen = NULL;
  55. struct ViewPort *VPort = NULL;
  56. struct UCopList    *CoprList = NULL;
  57. struct UCopList    *SaveList = NULL;
  58. long ASignal = -1;
  59.  
  60. long Count = 120;
  61.  
  62. /* Intuition Screen Specification */
  63. struct NewScreen ScreenSpec =
  64. {
  65.     0,0,
  66.     320,200,4,
  67.     0,0,0,
  68.     CUSTOMSCREEN,
  69.     0,
  70.     (UBYTE *) "Copper Example",
  71.     0
  72. };
  73.  
  74.  
  75. /* Interrupt Processing Code */
  76. VOID IntrProc()
  77. {
  78.     int_start();
  79.  
  80.     if (--Count <= 0) Signal(ATask,1 << ASignal);
  81.  
  82.     int_end();
  83. }
  84.  
  85.  
  86. main()
  87. {
  88.     MainInit();
  89.  
  90.     VPort = &AScreen->ViewPort;
  91.  
  92.     /* Save old user copper list */
  93.     SaveList = VPort->UCopIns;
  94.  
  95.     /* Build a Copper List */
  96.     CINIT(CoprList,100);
  97.     CWAIT(CoprList,100, 0); /* Video Line 100 */
  98.     CMOVE(CoprList,custom.intreq,INTF_SETCLR | INTF_COPER);
  99.     CEND(CoprList);
  100.  
  101.     /* Insert new user copper list */
  102.     VPort->UCopIns = CoprList;
  103.     MakeScreen(AScreen);
  104.     RethinkDisplay();
  105.  
  106.     /* Setup copper interrupt */
  107.     AddIntServer(INTB_COPER, Intr);
  108.  
  109.     /* Something else to do... */
  110.     while (Count > 0) printf("%d\n",Count);
  111.  
  112.     Wait(1 << ASignal);    /* Sync-up */
  113.  
  114.     /* Clean up */
  115.     RemIntServer(INTB_COPER, Intr);
  116.  
  117.     MainExit(0);
  118. }
  119.  
  120.  
  121. MainInit()
  122. {
  123.     extern APTR OpenLibrary();
  124.     extern struct Screen *OpenScreen();
  125.     extern struct Interrupt *MakeIntr();
  126.     extern long AllocSignal();
  127.     extern struct Task *FindTask();
  128.     extern void *AllocMem();
  129.     extern int Enable_Abort;
  130.  
  131.     Enable_Abort = 0;    /* prevent a CTRL-C */
  132.  
  133.     GfxBase = OpenLibrary("graphics.library", 30);
  134.     if (GfxBase == NULL) MainExit(201);
  135.  
  136.     IntuitionBase = OpenLibrary("intuition.library", 30);
  137.     if (GfxBase == NULL) MainExit(202);
  138.  
  139.     AScreen = OpenScreen(&ScreenSpec);
  140.     if (AScreen == NULL) MainExit(210);
  141.  
  142.     CoprList = AllocMem(sizeof(*CoprList), MEMF_CLEAR);
  143.     if (CoprList == NULL) MainExit(220);
  144.  
  145.     ASignal = AllocSignal(-1);
  146.     if (ASignal == -1) MainExit(230);
  147.  
  148.     Intr = MakeIntr("copper.example",0,&IntrProc,0);
  149.     if (Intr == NULL) MainExit(240);
  150.  
  151.     ATask = FindTask(NULL);
  152. }
  153.  
  154.  
  155. MainExit(error)
  156.     int error;
  157. {
  158.     if (AScreen != NULL) 
  159.     {
  160.         VPort->UCopIns = SaveList; /* restore it */
  161.         MakeScreen(AScreen);
  162.         RethinkDisplay();
  163.         CloseScreen(AScreen);
  164.     }
  165.  
  166.     if (CoprList != NULL)
  167.     {
  168.         /* Free intermediate copper list */
  169.         FreeCopList(CoprList->FirstCopList);
  170.  
  171.         FreeMem(CoprList,sizeof(*CoprList));
  172.     }
  173.  
  174.     FreeIntr(Intr);
  175.  
  176.     if (ASignal != -1) FreeSignal(ASignal);
  177.  
  178.     if (IntuitionBase != NULL)
  179.         CloseLibrary(IntuitionBase);
  180.  
  181.     if (GfxBase != NULL)
  182.         CloseLibrary(GfxBase);
  183.  
  184.     exit(error);
  185. }
  186.